package com.tarena.lbs.basic.web.controller;


import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.service.BusinessService;
import com.tarena.lbs.pojo.basic.param.BusinessParam;
import com.tarena.lbs.pojo.basic.query.BusinessQuery;
import com.tarena.lbs.pojo.basic.vo.BusiStoreVO;
import com.tarena.lbs.pojo.basic.vo.BusinessCategoryVO;
import com.tarena.lbs.pojo.basic.vo.BusinessVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class BusinessController {
    @Autowired
    private BusinessService businessService;
    //商家分页列表查询
    @GetMapping("/admin/basic/business/info/list")
    public Result<PageResult<BusinessVO>> businessPage(BusinessQuery query)
        throws BusinessException {
            PageResult<BusinessVO> voPages = businessService.businessPage(query);
            return new Result<>(voPages);
        }


     //商家行业分类列表查询list查询 查所以
    //select * from t_business_category
    @GetMapping("/admin/basic/business/category/list/")
    public Result<List<BusinessCategoryVO>> getAllCats() throws BusinessException{
        List<BusinessCategoryVO> vos = businessService.getAllCats();
        return new Result<>(vos);
    }

    //新增商家 不是表单格式:name=wch&age=18
    @PostMapping("/admin/basic/business/info/save")
    public Result<Void> businessSave(@RequestBody BusinessParam param)throws BusinessException{
        businessService.businessSave(param);
        return Result.success();
    }
    //随着互动 查询商家 以及商家下的店铺列表
    @GetMapping("/basic/business/info/detail/{id}")
    public Result<BusiStoreVO> businessStores(@PathVariable Integer id)
            throws BusinessException{
        BusiStoreVO vo=businessService.businessStore(id);
        return new Result<>(vo);
    }
}

